do reconstruct_extrad
set more off			 
capture ge dd1=tds==1
cap log close
log using model_spl_tw_tco_fx_WN_notime.log,replace			



cap drop bob0 bob1 bob2

ge bob0=bobt==0 & bobs==0
ge bob1=bobt==1 & bobs==1
ge bob2=bobt==2 & bobs==2

replace dd=1 if dd==. & yt==ys
replace dd=0 if dd==.


cap drop age_*
cap drop  agem1
ge agem1=agetA-1
mkspline age_1 4 age_2 9 age_3 15 age_4 19 age_5 26 age_6 = agem1



replace tds = abs(ys-yt) if tds ==.

cap drop startys
ge startys=(ys-(agesA))				
cap drop noverlap
ge noverlap = min(yt,ys) - startys 



capture program drop listpara
program define listpara
	version 5.0
	global listpar ""
	while "`1'"~=""	{
		global listpar "$listpar `1'"
		mac shift
	}
end
listpara sa0 sa1 sa2 sd sm  b30_0 b30_1 b30_2   





capture program drop droppi
program define droppi
	version 5.0
	while "`1'"~=""	{
		capture drop `1'
		mac shift
	}
end


droppi $listpar resi 




capture drop br1
capture drop br2
capture drop bc1 
capture drop bc2
capture gen br1=yt<=1991				 
capture gen br2=yt>1991

capture gen bc1=ys<=1991
capture gen bc2=ys>1991



capture program drop nlamft15
program define nlamft15
	version 5.0
	if "`1'"=="?" { 
		global S_1 "$listpar"
		nlinit .08 sa0 sa1 sa2 sd sm 
		nlinit .05 b30_0 b30_1 b30_2  


		exit
	}
	tempvar pv tv  pl tl  b3 beta30 beta31 beta32 b4 b30 sa   tco
	
*CORE PERMANENT

	quietly capture gen double `sa'= ($sa0*bob0 + $sa1*bob1 + $sa2*bob2)

	
	
	quietly capture gen double `pv'= (`sa' + $sm)  if (bobt==0&bobs==0)									
	quietly replace 		   `pv'= (`sa' + $sm + $sd  )  					if (bobt==1&bobs==1)|(bobt==2&bobs==2)
	quietly replace 		   `pv'= ($sm )  if (bobt==0&bobs>0)
	quietly replace 		   `pv'= ($sd + $sm )  if (bobt==1&bobs==2)


	
*CORE TRANSITORY
	
	quietly capture gen double `tv'= ($b30_0*bob0 + $b30_1*bob1 + $b30_2*bob2)*dd
	
	
*EVALUATOR
	quietly replace `1'=`pv'+`tv'
end 
nl amft15 m   dc* dr* , leave  eps(1e-4)






nlpred resi , resid
cap drop total
nlpred total



do diagncobis /*computes adjusted S.E. and Newey's chi2*/

mat list result

*********************************PREDICTIONS

cap program drop foo2
program define foo2, eclass
	tempname b V
	matrix `b' = e(b)
	matrix `V' = e(V)
	matrix define `V' = vp
	ereturn post `b' `V' 
end

foo2



nlcom (rhoI: _b[sm]/(_b[sm]+ _b[sd] + .5*_b[sa1]+ .5*_b[sa2]))  /*
	 */  (rhoB: (_b[sd] + _b[sm]) /(_b[sm]+ _b[sd] + .5*_b[sa1]+ .5*_b[sa2]))   /*
	 */ (rhoR: _b[sd]/(_b[sm]+ _b[sd] + .5*_b[sa1]+ .5*_b[sa2]))  /*
	*/ 	   (shareI:  _b[sm]/(_b[sm]+ _b[sd]))



log close

